<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在职证明模版</title>
    <link href="../css/all.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f4f4f5;
            font-family: "SimSun", sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }

       .a4-container {
            width: 210mm;
            min-height: 297mm;
            padding: 32px;
            background-color: #fff;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            border-radius: 8px;
            position: relative;
            box-sizing: border-box;
        }

       .title {
            font-size: 22px;
            font-weight: bold;
            text-align: center;
            color: #000;
            margin-bottom: 24px;
        }

       .content-text {
            color: #000;
            line-height: 1.75;
            margin-bottom: 16px;
            text-indent: 2em;
        }

       .rule-list {
            list-style-type: decimal;
            padding-left: 24px;
            color: #000;
            line-height: 1.75;
            margin-bottom: 32px;
        }

       .underline-text {
            border-bottom: 1px solid #9ca3af;
            padding: 0 8px;
            cursor: pointer;
        }

       .print-button {
            position: fixed;
            top: 50%;
            right: 20px;
            transform: translateY(-50%);
            padding: 10px 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

       .print-button:hover {
            background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
        }

       .signature-section {
            text-align: right;
            margin-top: 50px;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            position: relative;
        }

       .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
            justify-content: center;
            align-items: center;
        }

       .modal-content {
            background: linear-gradient(135deg, #f9f9f9, #e6e6e6);
            padding: 30px;
            border: 1px solid #888;
            width: 400px;
            border-radius: 15px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
            text-align: center;
            animation: fadeIn 0.3s ease-out;
        }

       .close {
            color: #aaa;
            position: absolute;
            top: 10px;
            right: 20px;
            font-size: 28px;
            font-weight: bold;
        }

       .close:hover,
       .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }

       .modal-button {
            padding: 12px 25px;
            margin: 0 10px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            font-size: 16px;
        }

       .modal-button.save {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

       .modal-button.save:hover {
             background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
        }

       .modal-button.clear {
            background: linear-gradient(135deg, #9ca3af 0%, #6f6c6c 100%);
            color: white;
        }

       .modal-button.clear:hover {
            background: linear-gradient(135deg, #6f6c6c 0%, #9ca3af 100%);
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @media print {
            body {
                background-color: transparent;
            }

           .a4-container {
                box-shadow: none;
                border-radius: 0;
                width: 210mm;
                min-height: 297mm;
                margin: 0;
                padding: 32px;
                page-break-after: avoid;
            }

           .print-button {
                display: none;
            }

           .modal {
                display: none !important;
            }
        }

       .editable {
            border-bottom: 1px solid #000;
            outline: none;
            display: inline-block;
            text-indent: 0px;
        }

       .custom-file-upload {
            display: inline-block;
            padding: 12px 25px;
            background: linear-gradient(135deg, #9ca3af 0%, #6f6c6c 100%);
            color: white;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            margin-bottom: 20px;
        }

       .custom-file-upload:hover {
            background: linear-gradient(135deg, #6f6c6c 0%, #9ca3af 100%);
        }

       .custom-file-upload input[type="file"] {
            display: none;
        }

       .preview-image {
            max-width: 100%;
            max-height: 200px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

       .button-container {
            display: flex;
            justify-content: center;
        }
    </style>
</head>

<body>
    <div class="a4-container">
        <h1 class="title">在职证明</h1>
        <p class="content-text">兹证明 <span class="editable" contenteditable="true" data-default="[员工姓名]">[员工姓名]</span>，性别 <span class="editable" contenteditable="true" data-default="[性别]">[性别]</span>，身份证号为 <span class="editable" contenteditable="true" data-default="[身份证号]">[身份证号]</span>，自 <span class="editable" contenteditable="true" data-default="[入职日期]">[入职日期]</span> 起至今在本单位工作，目前在 <span class="editable" contenteditable="true" data-default="[部门名称]">[部门名称]</span> 担任 <span class="editable" contenteditable="true" data-default="[职位名称]">[职位名称]</span> 一职。</p>
        <p class="content-text">该员工在本单位工作期间，遵守公司规章制度，工作态度认真负责，具备良好的职业素养和专业技能。</p>
        <p class="content-text" style="padding-top:20px;">特此证明</p>
        <p class="content-text">注：本在职证明仅用于 <span class="editable" contenteditable="true" data-default="XXX">XXX</span>，不作为其他用途担保，他用无效</p>
        <div class="signature-section">
            <p class="content-text">单位盖章：<span id="signature-line" class="underline-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
            <p class="content-text" style="text-align: right; text-indent: 0;">单位地址：<span class="editable" contenteditable="true" data-default="[单位地址]">[单位地址]</span></p>
            <p class="content-text" style="text-align: right; text-indent: 0;">单位联系人：<span class="editable" contenteditable="true" data-default="[单位联系人]">[单位联系人]</span></p>
            <p class="content-text" style="text-align: right; text-indent: 0;">单位电话：<span class="editable" contenteditable="true" data-default="[单位电话]">[单位电话]</span></p>
            <p class="content-text">日期：<span id="current-date" class="editable" contenteditable="true" data-default="[签字日期]">[签字日期]</span></p>
        </div>
        
    </div>
    <button class="print-button" onclick="window.print()">打印</button>

    <!-- 盖章模态框 -->
    <div id="myModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <h2>选择本地盖章图片</h2>
            <label for="stampFile" class="custom-file-upload">
                选择文件
                <input type="file" id="stampFile" accept="image/*" onchange="previewImage(this)">
            </label>
            <div class="preview-image">
                <img id="preview" src="#" alt="预览图片" style="display: none;">
            </div>
            <div class="button-container">
                <button class="modal-button save" onclick="saveStamp()">保存盖章</button>
                <button class="modal-button clear" onclick="clearStamp()">清除选择</button>
            </div>
        </div>
    </div>

    <script>
        const currentDate = new Date();
        const year = currentDate.getFullYear();
        const month = String(currentDate.getMonth() + 1).padStart(2, '0');
        const day = String(currentDate.getDate()).padStart(2, '0');
        document.getElementById('current-date').textContent = `${year}年${month}月${day}日`;

        const signatureLine = document.getElementById('signature-line');
        const modal = document.getElementById('myModal');
        const closeBtn = document.querySelector('.close');
        const stampFile = document.getElementById('stampFile');
        const preview = document.getElementById('preview');

        signatureLine.addEventListener('click', function () {
            modal.style.display = 'flex';
        });

        closeBtn.addEventListener('click', function () {
            modal.style.display = 'none';
        });

        window.addEventListener('click', function (event) {
            if (event.target === modal) {
                modal.style.display = 'none';
            }
        });

        function previewImage(input) {
            if (input.files && input.files[0]) {
                const reader = new FileReader();
                reader.onload = function (e) {
                    preview.src = e.target.result;
                    preview.style.display = 'block';
                };
                reader.readAsDataURL(input.files[0]);
            } else {
                preview.src = '#';
                preview.style.display = 'none';
            }
        }

        function saveStamp() {
            const file = stampFile.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function (e) {
                    const img = new Image();
                    img.src = e.target.result;
                    img.style.width = '200px';
                    img.style.position = 'absolute';
                    img.style.bottom = '150px';
                    img.style.right = '0';
                    img.style.zIndex = 1;
                    img.style.opacity = 0.8;
                    signatureLine.appendChild(img);
                    modal.style.display = 'none';
                };
                reader.readAsDataURL(file);
            }
        }

        function clearStamp() {
            stampFile.value = '';
            preview.src = '#';
            preview.style.display = 'none';
        }

        const editableElements = document.querySelectorAll('.editable');
        editableElements.forEach(element => {
            element.addEventListener('focus', function () {
                setTimeout(() => {
                    if (this.textContent === this.dataset.default) {
                        this.textContent = '';
                        this.style.color = '#000';
                    }
                }, 0);
            });
            element.addEventListener('blur', function () {
                if (this.textContent === '') {
                    this.textContent = this.dataset.default;
                    this.style.color = '#777';
                }
            });
        });
    </script>
</body>

</html>